A veces, si tenemos pocos datos no es necesario incluir una tabla dinámica. Para incluir una tabla estática, usamos una instrucción knitr::kable(dataframe) dentro del bloque de código R que dibuja la tabla:
| CURSO | TOTAL_HOMBRES | TOTAL_MUJERES |
|---|---|---|
| 2007-2008 | 22107 | 37041 |
| 2008-2009 | 21652 | 36047 |
| 2009-2010 | 21502 | 35007 |
| 2010-2011 | 20814 | 33868 |
| 2011-2012 | 21490 | 34415 |
| 2012-2013 | 24356 | 40511 |
| 2013-2014 | 23472 | 38470 |
| 2014-2015 | 22501 | 36426 |
| 2015-2016 | 22004 | 35784 |
| 2016-2017 | 21245 | 34127 |
| 2017-2018 | 20273 | 32849 |
| 2018-2019 | 19767 | 32445 |
| 2019-2020 | 19630 | 32533 |
| 2020-2021 | 19066 | 32314 |
| 2021-2022 | 17643 | 30628 |
| 2022-2023 | 17558 | 30491 |
Para las tablas dinámicas usando DT escribimos el siguiente bloque de código R:
Markdown permite introducir código HTML directamente. Para dibujar imágenes en el dashboard, escribimos el siguiente código HTML en la componente donde queramos dibujar la imagen.
---
title: "Alumnado UCM"
author: "Pedro de la Muela"
date: "`r Sys.Date()`"
output:
flexdashboard::flex_dashboard:
source_code: embed
logo: logos/woman.png
favicon: logo/ucm:favicon.png
social: [ "twitter", "facebook", "menu"]
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readr)
library(ggplot2)
library(DT)
library(plotly)
df <- read_delim("datos_tratados.csv", delim = ";")
df$CURSO <- factor(df$CURSO)
df$CENTRO <- factor(df$CENTRO)
```
# Página 1
## Columna 1
### Tabla estática {data-height=300}
A veces, si tenemos pocos datos no es necesario incluir una tabla dinámica. Para incluir una tabla estática, usamos una instrucción **knitr::kable(dataframe)** dentro del bloque de código R que dibuja la tabla:
```r
grouped_data <- df %>%
group_by(CURSO) %>%
select(CURSO, TOTAL_HOMBRES, TOTAL_MUJERES) %>%
summarise(across(where(is.numeric), sum))
knitr::kable(grouped_data)
```
### Tabla estática
```{r}
grouped_data <- df %>%
group_by(CURSO) %>%
select(CURSO, TOTAL_HOMBRES, TOTAL_MUJERES) %>%
summarise(across(where(is.numeric), sum))
knitr::kable(grouped_data)
```
## Columna 2
### Tabla dinámica con DT {data-height=300}
Para las tablas dinámicas usando DT escribimos el siguiente bloque de código R:
```r
grouped_data <- df %>%
group_by(CURSO) %>%
select(CURSO, TOTAL_HOMBRES, TOTAL_MUJERES) %>%
summarise(across(where(is.numeric), sum))
DT::datatable(grouped_data, options = list( pageLength = 15))
```
[Sintaxis Markdown para incluir código R entre el texto](https://www.markdownguide.org/extended-syntax/#syntax-highlighting)
### Tabla dinámica
```{r}
grouped_data <- df %>%
group_by(CURSO) %>%
select(CURSO, TOTAL_HOMBRES, TOTAL_MUJERES) %>%
summarise(across(where(is.numeric), sum))
DT::datatable(grouped_data, options = list( pageLength = 15))
```
# Página 2
## Columna 1
### Imágenes dentro de un componente {data-height=300}
Markdown permite introducir código HTML directamente. Para **dibujar imágenes en el dashboard**, escribimos el siguiente **código HTML** en la componente donde queramos dibujar la imagen.
```r
<img src="./logos/ucm_favicon.png" width="100" >
```
### Resultado de dibujar una imagen
<img src="./logos/ucm_favicon.png" width="100" >
## Columna 2
### Componente {.no-title}
```{r}
datos_totales <- read_delim("datos_totales_largo.csv", delim = ";")
g1 <- ggplot(datos_totales, aes(x = CURSO, y = total, fill = Género)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Total de Alumnos",
x = "CURSO",
y = "Total") +
scale_fill_manual(values = c("TOTAL_MUJERES" = "blue", "TOTAL_HOMBRES" = "red")) + theme(axis.text.x = element_text(angle = 30, vjust = 1, hjust = 1, size = 8))
g2 <- ggplotly(g1)
g2
```